package com.corejava.training.collections.car.pre15;

import java.util.*;

public class LaptopMutableDemo {

	public static void main(String[] args) {

		// instantiate Laptop objects/instances and set values
		LaptopMutable lap1 = new LaptopMutable();
		lap1.setCompany("Dell");
		lap1.setModel("Latitude");
		lap1.setOs("Windows XP");
		lap1.setProcessor(2.6);

		LaptopMutable lap2 = new LaptopMutable();
		lap2.setCompany("HP");
		lap2.setModel("Pavillion");
		lap2.setOs("Windows Vista");
		lap2.setProcessor(2.8);

		LaptopMutable lap3 = new LaptopMutable();
		lap3.setCompany("Apple");
		lap3.setModel("Macbook");
		lap3.setOs("Mac OS");
		lap3.setProcessor(3.0);

		LaptopMutable lap4 = new LaptopMutable();
		lap4.setCompany("Dell");
		lap4.setModel("Latitude");
		lap4.setOs("Windows 7");
		lap4.setProcessor(2.9);

		// add laptop instances/objects to list
		List lapList = new ArrayList();
		lapList.add(lap1);
		lapList.add(lap2);
		lapList.add(lap3);

		// add laptop instances in Set

		Set<LaptopMutable> laptopList = new HashSet<LaptopMutable>();
		laptopList.add(lap1);
		laptopList.add(lap2);
		laptopList.add(lap4);

		// now read laptops from the Set and print them out, Set does not allow
		// duplication, java 1.4 style
		
		Iterator ite = laptopList.iterator();
		while (ite.hasNext()) {
			LaptopMutable alaptop = (LaptopMutable) ite.next();
			System.out.println("Company: " + alaptop.getCompany());
			System.out.println("Model: " + alaptop.getModel());
			System.out.println("OS: " + alaptop.getOs());
			System.out.println("Processor: " + alaptop.getProcessor());
			System.out.println("-----------------------------------------");

		}

		// read laptop objects from the list and print out with 1.4 style
		
		Iterator iter = lapList.iterator();
		while (iter.hasNext()) {
			LaptopMutable alaptop = (LaptopMutable) ite.next();
			System.out.println("Company: " + alaptop.getCompany());
			System.out.println("Model: " + alaptop.getModel());
			System.out.println("OS: " + alaptop.getOs());
			System.out.println("Processor: " + alaptop.getProcessor());
			System.out.println("-----------------------------------------");

		}
	}

} // end of class
